﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace 书易.WEB
{
    public partial class Code : System.Web.UI.Page
    {
        private static string libs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890123456789012345678901234567890123456789";
        private Random dr = new Random();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack){
                string code = "";
                for (int i = 0; i < 4; i++)
                {
                    code += libs[dr.Next(libs.Length)];
                }

                Session["code"] = code;

                Bitmap b = new Bitmap(100, 30);

                Graphics g = Graphics.FromImage(b);

                g.Clear(Color.White);

                g.DrawString(code,new Font("楷体",15),Brushes.Red,2,2);

                Response.ContentType = "image/gif";

                b.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif);
            }
        }
    }
}